package cn.tedu.apiday07;
//售票窗口案例方式2 实现Runnable接口
public class Text1 {
    public static void main(String[] args) {
        MyTickets1 my = new MyTickets1();
//        MyTickets1 my1 = new MyTickets1();
//        MyTickets1 my2 = new MyTickets1();
//        MyTickets1 my3 = new MyTickets1();
        Thread t = new Thread(my);
        Thread t1 = new Thread(my);
        Thread t2 = new Thread(my);
        Thread t3 = new Thread(my);
        t.setName("1号窗口");
        t1.setName("2号窗口");
        t2.setName("3号窗口");
        t3.setName("4号窗口");
        t.start();
        t1.start();
        t2.start();
        t3.start();


    }
}
class MyTickets1 implements  Runnable{
    static int tickets = 100;

    @Override
    public void run() {
        while (true){
            if (tickets>0){
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName()+"==========="+tickets--);//获取线程名称
            } else {
                break;
            }
        }
    }
}